package com.imcrl.piano.mvc.view.listItem
{
	import com.imcrl.piano.core.Assets;
	import com.imcrl.piano.core.KeyAssets;
	import com.imcrl.piano.mvc.model.vo.NoetsDefVO;
	import com.imcrl.piano.utils.SpriteUtils;
	
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;

	public class NoetsItemRender extends Sprite
	{
		
		private static var keyAssets:KeyAssets;
		
		private var _data:NoetsDefVO;
		private var _icon:DisplayObject
		public function NoetsItemRender()
		{
			if(keyAssets==null)keyAssets=new KeyAssets();
		}
		
		public function set data(value:NoetsDefVO):void{
			if(_data==value)return;
			
			if(_data){
				_data.removeEventListener(Event.CHANGE,dataInnerChangeHandler);
			}
			
			_data=value;
			_data.addEventListener(Event.CHANGE,dataInnerChangeHandler,false,0,true);
			
			_icon=keyAssets.getView(value.node-1);
			
			SpriteUtils.clear(this);
			
			var g:Graphics=this.graphics;
			g.clear();
			
			g.lineStyle(3,0xFFFFFF,0.6)
			g.moveTo(0,0);
			g.lineTo(0,_icon.height);
			
			
			if(_data.duration>= 600){
				g.lineStyle(6,0xFFFFFF,0.6)
				g.moveTo(0,0)
				g.lineTo(0.1*_data.duration,0)
			}
			
			
			_icon.x=-(_icon.width>>1);
			_icon.y=-(_icon.height>>1);
			
			this.addChild(_icon);
		}
		
		private function dataInnerChangeHandler(event:Event):void{
			if(_data.b){
				this.alpha=.3
			}else{
				this.alpha=1;
			}
		}
		
	}
}